package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.WebsiteInfo;
import com.ruoyi.system.domain.vo.WebsiteCategoryVo;
import com.ruoyi.system.mapper.WebsiteInfoMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WebsiteCategoryMapper;
import com.ruoyi.system.domain.WebsiteCategory;
import com.ruoyi.system.service.IWebsiteCategoryService;

/**
 * websiteCategoryService业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-28
 */
@Service
public class WebsiteCategoryServiceImpl implements IWebsiteCategoryService 
{
    @Autowired
    private WebsiteCategoryMapper websiteCategoryMapper;

    @Autowired
    private WebsiteInfoMapper websiteInfoMapper;

    /**
     * 查询websiteCategory列表和分类信息
     *
     * @param websiteCategory websiteCategory
     * @return websiteCategory
     */
    @Override
    public List<WebsiteCategoryVo> selectWebsiteCategoryAndInfoList(WebsiteCategory websiteCategory)
    {
        List<WebsiteCategoryVo> websiteCategoryVoList = new ArrayList<>();
        List<WebsiteCategory> websiteCategoryList = websiteCategoryMapper.selectWebsiteCategoryList(websiteCategory);
        for (WebsiteCategory category : websiteCategoryList) {
            WebsiteCategoryVo websiteCategoryVo = new WebsiteCategoryVo();
            WebsiteInfo websiteInfo = new WebsiteInfo();
            websiteInfo.setWebsiteCategory(category.getId());
            List<WebsiteInfo> websiteInfos = websiteInfoMapper.selectWebsiteInfoList(websiteInfo);
            BeanUtils.copyProperties(category,websiteCategoryVo);
            websiteCategoryVo.setWebsiteInfoList(websiteInfos);
            websiteCategoryVoList.add(websiteCategoryVo);
        }
        return websiteCategoryVoList;
    }



    /**
     * 查询websiteCategory
     * 
     * @param id websiteCategory主键
     * @return websiteCategory
     */
    @Override
    public WebsiteCategory selectWebsiteCategoryById(Long id)
    {
        return websiteCategoryMapper.selectWebsiteCategoryById(id);
    }


    /**
     * 查询websiteCategory列表
     * 
     * @param websiteCategory websiteCategory
     * @return websiteCategory
     */
    @Override
    public List<WebsiteCategory> selectWebsiteCategoryList(WebsiteCategory websiteCategory)
    {
        return websiteCategoryMapper.selectWebsiteCategoryList(websiteCategory);
    }

    /**
     * 新增websiteCategory
     * 
     * @param websiteCategory websiteCategory
     * @return 结果
     */
    @Override
    public int insertWebsiteCategory(WebsiteCategory websiteCategory)
    {
        return websiteCategoryMapper.insertWebsiteCategory(websiteCategory);
    }

    /**
     * 修改websiteCategory
     * 
     * @param websiteCategory websiteCategory
     * @return 结果
     */
    @Override
    public int updateWebsiteCategory(WebsiteCategory websiteCategory)
    {
        return websiteCategoryMapper.updateWebsiteCategory(websiteCategory);
    }

    /**
     * 批量删除websiteCategory
     * 
     * @param ids 需要删除的websiteCategory主键
     * @return 结果
     */
    @Override
    public int deleteWebsiteCategoryByIds(Long[] ids)
    {
        return websiteCategoryMapper.deleteWebsiteCategoryByIds(ids);
    }

    /**
     * 删除websiteCategory信息
     * 
     * @param id websiteCategory主键
     * @return 结果
     */
    @Override
    public int deleteWebsiteCategoryById(Long id)
    {
        return websiteCategoryMapper.deleteWebsiteCategoryById(id);
    }
}
